package com.xiaoshuidi.cloud.module.rooms.job.delayjob.strategy;

import com.xiaoshuidi.cloud.module.rooms.enums.DelayJobType.DelayJobTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Component
public class ProcessingTask {
    @Resource
    private DepositPaymentTermStrategy depositPaymentTermStrategy;
    @Resource
    private ExpirationDateStrategy expirationDateStrategy;


    private static Map<DelayJobTypeEnum, IStrategy> iStrategyMap = new HashMap<DelayJobTypeEnum, IStrategy>();

    @PostConstruct
    public void post(){
        iStrategyMap.put(DelayJobTypeEnum.DEPOSIT_PAYMENT_TERM, depositPaymentTermStrategy);
        iStrategyMap.put(DelayJobTypeEnum.EXPIRATION_DATE, expirationDateStrategy);
    }

    public IStrategy getStrategy(DelayJobTypeEnum key) {
        IStrategy iStrategy = iStrategyMap.get(key);
        if(iStrategy == null){
            throw new RuntimeException("策略有误");
        }
        return iStrategy;
    }
}
